﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System
{
    public static class URIExtensions
    {
        public static string GetQueryString(this Uri uri, string name)
        {
            try
            {
                string url_string = uri.OriginalString;
                string[] parts = url_string.Split('?');
                string[] querystring = parts[1].Split('&');
                foreach (string name_value_pair in querystring)
                {
                    string[] nvpair_parts = name_value_pair.Split('=');
                    if (nvpair_parts[0].Trim() == name)
                        return nvpair_parts[1];
                }
            }
            catch (Exception ex)
            {

            }
            return null;
        }
    }
}
